package com.guoxin.designpattern.chapter7;

import java.util.concurrent.CountDownLatch;
import java.util.stream.IntStream;

/**
 * @author guoxin
 * @date 2019/9/5
 */
public class ImmutablePerformanceUseThread {
    public static void main(String[] args) throws InterruptedException {
        long startTime = System.currentTimeMillis();
        CountDownLatch latch = new CountDownLatch(2);
        SyncObj obj = new SyncObj(); //139765
        obj.setName("Tom");

//        ImmutableObj obj = new ImmutableObj("Tom");//116791
        IntStream.range(0, 2).forEach(i -> new Thread(() -> {
            IntStream.range(0, 1000000).forEach(i1 -> System.out.println(Thread.currentThread().getName()+"--"+obj.toString()));
            latch.countDown();
        }).start());
        latch.await();
        long endTime = System.currentTimeMillis();
        System.out.println("Elapsed time " + (endTime - startTime));

    }
}
